package com.internetCafes.spms.common.AIRecognize.analyzer.impl;

import com.internetCafes.spms.common.CommonConstants;
import com.internetCafes.spms.common.AIRecognize.analyzer.Analyzer;
import com.internetCafes.spms.common.AIRecognize.handler.impl.HtmlURLHandler;
import com.internetCafes.spms.common.AIRecognize.handler.impl.JsonURLHandler;
import com.internetCafes.spms.common.AIRecognize.QRCodeRecognizeUtils;
import com.internetCafes.spms.web.certificate.vo.AIRecognizeInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author LinYe
 * @date 2020/10/14
 */
@Component
public class URLAnalyzer implements Analyzer {

    @Autowired
    private HtmlURLHandler htmlURLHandler;

    @Autowired
    private JsonURLHandler jsonURLHandler;

    @Override
    public AIRecognizeInfo analyze(String url, String filePath) {
        url = QRCodeRecognizeUtils.subSuffix(url);
        if (url.contains(CommonConstants.QRCodeRecognizeUrlType.TRANSPORT_THREE_WEB)
                || url.contains(CommonConstants.QRCodeRecognizeUrlType.NATION_CERTIFICATE_WEB)) {
            return htmlURLHandler.handle(url, filePath);
        }
        if (url.contains(CommonConstants.QRCodeRecognizeUrlType.ZJ_GOV_WEB)
                || url.contains(CommonConstants.QRCodeRecognizeUrlType.WATER_RESOURCE_THREE_WEB)) {
            return jsonURLHandler.handle(url, filePath);
        }
        return null;
    }

    @Override
    public boolean match(String urlOrWord) {
        if (urlOrWord.startsWith("http:")) {
            return true;
        }
        return false;
    }
}
